package com.controls.utils
{
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.navigateToURL; 
	
	public class WebWindow 
	{ 
		public function WebWindow(url:String, window:String="_blank", features:String="")
		{ 
			var WINDOW_OPEN_FUNCTION:String = "window.open"; 
			var myURL:URLRequest = new URLRequest(url);    
			var browserName:String = getBrowserName(); 
			
			if(browserName == "maxthon"){ 
				ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features); 
			} 
			else if(browserName == "firefox"){ 
				navigateToURL(myURL, window); 
			} 
			else if(browserName == "chrome"){      
				navigateToURL(myURL, window); 
			} 
			else if(browserName == "msie"){      
				navigateToURL(myURL, window); 
//				ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features); 
			}  
			else if(browserName == "safari"){ 
				ExternalInterface.call(WINDOW_OPEN_FUNCTION, url, window, features); 
			} 
			else { 
				navigateToURL(myURL, window); 
			} 
		} 
		public function getBrowserName():String{ 
			var browser:String; 
			
			var browserAgent:String = ExternalInterface.call("function getBrowser(){return navigator.userAgent.toLowerCase();}"); 
			
			if(browserAgent != null && /(.*)maxthon(.*)/.test(browserAgent)) { 
				browser = "maxthon"; 
			}  
			else if(browserAgent != null && /(.*)firefox(.*)/.test(browserAgent)){ 
				browser = "firefox"; 
			}     
			else if(browserAgent != null && /(.*)chrome(.*)/.test(browserAgent)){ 
				browser = "chrome"; 
			}    
			else if(browserAgent != null && /(.*)msie(.*)/.test(browserAgent)){ 
				browser = "msie"; 
			} 
			else if(browserAgent != null && /(.*)mozilla(.*)/.test(browserAgent) && !/(.*)firefox(.*)/.test(browserAgent) && !/(.*)chrome(.*)/.test(browserAgent) && !/(.*)msie(.*)/.test(browserAgent)){ 
				browser = "safari"; 
			} 
			
			return browser; 
		} 
	} 
}